<template>

    <div>
        <div style="float: left;">
            <div style="left:100px;width: 100;">
                <img :src="tablelist.goodImages" style="width: 300px; height: 300px;" />
            </div>
        </div>
        <div style="float: left; margin-left: 10px;">

            <h1>{{ tablelist.goodName }}</h1>
            <span>
                生产批次: {{ tablelist.batch }}&ensp;&ensp;&ensp;
                保质期: {{ tablelist.shelflife }}
            </span>
            <br /><br />
            <span>
                生产许可证号: {{ tablelist.production }}&ensp;&ensp;
                生产企业: {{ tablelist.goodCompany }}
            </span>

            <br /><br />
            <b style="font-weight: bolder;">产品检验报告<br />
                <el-carousel style="width: 100px; height: 100px">
                    <el-carousel-item>
                        <img :src="tablelist.goodImages" alt="" style="width: 100px; height: 100px">
                    </el-carousel-item>
                </el-carousel>
            </b>

        </div>
    </div>
    <br /><br /><br /><br /><br /><br />
    <br /><br /><br /><br /><br /><br />
    <br /><br /><br />
    <el-button type="primary" @click="yangs">养殖信息</el-button>&ensp;&ensp;&ensp;
    <el-button type="primary" @click="tus">屠宰信息</el-button>&ensp;&ensp;&ensp;
    <el-button type="primary" @click="shens">深加工</el-button>&ensp;&ensp;&ensp;

    <div v-if="yang">
        <span style="font-weight: bolder;">
            养殖信息&ensp;&ensp;&ensp;
            <el-button plain type="primary" @click="breeds">设置</el-button>
            <div>
                <span>
                    品种: {{ breedlist.breedName }}&ensp;&ensp;&ensp;
                    来源: {{ breedlist.breedCome }}
                </span>
                <br /><br />

                <span>
                    饲养天数: {{ breedlist.breedDay }}&ensp;&ensp;
                    饲料品牌: {{ breedlist.breedBrand }}
                </span>
                <br /><br />

                <span>
                    饲养负责人: {{ breedlist.breedPerson }}&ensp;&ensp;
                    出栏日期: {{ breedlist.breedPut }}
                </span>
            </div>
        </span>

        <el-dialog v-model="dialogVisibleyangadd" title="养殖信息添加" width="500">
            <el-form :model="breedadd" label-width="auto" style="max-width: 600px">
                <el-form-item label="品种" prop="breedName">
                    <el-input v-model="breedadd.breedName" />
                </el-form-item>
                <el-form-item label="来源" prop="breedCome">
                    <el-input v-model="breedadd.breedCome" />
                </el-form-item>
                <el-form-item label="饲养天数" prop="breedDay">
                    <el-input v-model="breedadd.breedDay" />
                </el-form-item>
                <el-form-item label="饲料品牌" prop="breedBrand">
                    <el-input v-model="breedadd.breedBrand" />
                </el-form-item>
                <el-form-item label="饲养负责人" prop="breedPerson">
                    <el-input v-model="breedadd.breedPerson" />
                </el-form-item>
                <el-form-item label="出栏日期" prop="breedPut">
                    <el-input v-model="breedadd.breedPut" />
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" @click="yangadd">新增</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog v-model="dialogVisibleyanngxiu" title="养殖信息修改" width="500">
            <el-form :model="breedupd" label-width="auto" style="max-width: 600px">
                <el-form-item label="品种" prop="breedName">
                    <el-input v-model="breedupd.breedName" />
                </el-form-item>
                <el-form-item label="来源" prop="breedCome">
                    <el-input v-model="breedupd.breedCome" />
                </el-form-item>
                <el-form-item label="饲养天数" prop="breedDay">
                    <el-input v-model="breedupd.breedDay" />
                </el-form-item>
                <el-form-item label="饲料品牌" prop="breedBrand">
                    <el-input v-model="breedupd.breedBrand" />
                </el-form-item>
                <el-form-item label="饲养负责人" prop="breedPerson">
                    <el-input v-model="breedupd.breedPerson" />
                </el-form-item>
                <el-form-item label="出栏日期" prop="breedPut">
                    <el-input v-model="breedupd.breedPut" />
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" @click="yangxiu">保存</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
        <br />
        <span style="font-weight: bolder;">
            保健信息&ensp;&ensp;&ensp;
        </span>

        <el-button plain type="primary" @click="healths">新增行</el-button>

        <el-table :data="healthlist" style="width:200%;">
            <el-table-column prop="healthDay" label="饲养天数" />
            <el-table-column prop="healthStyle" label="保健方式" />
            <el-table-column prop="healthIdea" label="保健方法" />
            <el-table-column label="操作" width="200px">
                <template #default="scope">
                    <el-button type="primary" @click="healthxiu()">修改</el-button>
                    <el-button type="danger" @click="healthdel(scope.row.goodInfoId)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <el-dialog v-model="dialogVisiblehealthxiu" title="保健信息修改" width="500">
            <el-form :model="healthupds" label-width="auto" style="max-width: 600px">
                <el-form-item label="饲养天数" prop="healthDay">
                    <el-input v-model="healthupds.healthDay" />
                </el-form-item>
                <el-form-item label="保健方式" prop="healthStyle">
                    <el-input v-model="healthupds.healthStyle" />
                </el-form-item>
                <el-form-item label="保健方法" prop="healthIdea">
                    <el-input v-model="healthupds.healthIdea" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="healthupd">保存</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
        <br />
        <span style="font-weight: bolder;">
            动检证&ensp;&ensp;&ensp;<br />
            <el-upload multiple v-model:file-list="fileList" :on-success="outUPload"
                action="http://localhost:5287/api/Breed/UploadFile" list-type="picture-card"
                :on-preview="handlePictureCardPreview" name="file">
                <el-icon>
                    <Plus />
                </el-icon>
            </el-upload>

            <el-dialog :visible.sync="dialogVisible" width="50%">
                <img :src="dialogImageUrl" class="preview-img" />
            </el-dialog>
        </span>


        <span style="font-weight: bolder;">
            企业信息&ensp;&ensp;&ensp;
        </span>

        <el-button plain type="primary" @click="yangcompany">设置</el-button>
        <div>
            <span>
                养殖场: {{ ycompanyshow.companyName }}&ensp;&ensp;&ensp;
                负责人: {{ ycompanyshow.companyBoss }}总
            </span>
            <br /><br />

            <span>
                存栏数量: {{ ycompanyshow.companyNumber }}只
            </span>
        </div>

        <el-dialog v-model="dialogVisiblecompanyxiu" title="企业信息设置" width="500">
            <el-form :model="ycompanyupd" label-width="auto" style="max-width: 600px">
                <el-form-item label="养殖场" prop="companyName">
                    <el-input v-model="ycompanyupd.companyName" />
                </el-form-item>
                <el-form-item label="负责人" prop="companyBoss">
                    <el-input v-model="ycompanyupd.companyBoss" />
                </el-form-item>
                <el-form-item label="存栏数量" prop="companyNumber">
                    <el-input v-model="ycompanyupd.companyNumber" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="Ycomanyupd">修改</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <br />
        <span style="font-weight: bolder;">
            企业照片&ensp;&ensp;&ensp;<br />
            <el-upload multiple v-model:file-list="fileListY" :on-success="outUPloadY"
                action="http://localhost:5287/api/Breed/UploadFile" list-type="picture-card"
                :on-preview="handlePictureCardPreview" name="file">
                <el-icon>
                    <Plus />
                </el-icon>
            </el-upload>

            <el-dialog :visible.sync="dialogVisible" width="50%">
                <img :src="dialogImageUrl" class="preview-img" />
            </el-dialog>
        </span>


    </div>

    <div v-if="tu">
        <span style="font-weight: bolder;">
            屠宰信息&ensp;&ensp;&ensp;
            <el-button plain type="primary" @click="butchers">设置</el-button>
            <div>
                <span>
                    批次: {{ butcherlist.butcherBatch }}&ensp;&ensp;&ensp;
                    到厂均重: {{ butcherlist.butcherWeight }}
                </span>
                <br /><br />
                <span>
                    到厂时间: {{ butcherlist.butcherStime }}&ensp;&ensp;
                    屠宰时间: {{ butcherlist.butcherEtime }}
                </span>
            </div>
        </span>

        <el-dialog v-model="dialogVisibletuadd" title="屠宰信息添加" width="500">
            <el-form :model="butcheradd" label-width="auto" style="max-width: 600px">
                <el-form-item label="批次" prop="butcherBatch">
                    <el-input v-model="butcheradd.butcherBatch" />
                </el-form-item>
                <el-form-item label="到厂均重（公斤）" prop="butcherWeight">
                    <el-input v-model="butcheradd.butcherWeight" />
                </el-form-item>
                <el-form-item label="到厂时间" prop="butcherStime">
                    <el-input v-model="butcheradd.butcherStime" />
                </el-form-item>
                <el-form-item label="屠宰时间" prop="butcherEtime">
                    <el-input v-model="butcheradd.butcherEtime" />
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" @click="tuadd">新增</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog v-model="dialogVisibletuxiu" title="屠宰信息修改" width="500">
            <el-form :model="butcherupd" label-width="auto" style="max-width: 600px">
                <el-form-item label="批次" prop="butcherBatch">
                    <el-input v-model="butcherupd.butcherBatch" />
                </el-form-item>
                <el-form-item label="到厂均重（公斤）" prop="butcherWeight">
                    <el-input v-model="butcherupd.butcherWeight" />
                </el-form-item>
                <el-form-item label="到厂时间" prop="butcherStime">
                    <el-input v-model="butcherupd.butcherStime" />
                </el-form-item>
                <el-form-item label="屠宰时间" prop="butcherEtime">
                    <el-input v-model="butcherupd.butcherEtime" />
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" @click="tuxiu">保存</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <br />
        <span style="font-weight: bolder;">
            相关资质&ensp;&ensp;&ensp;
            <el-upload multiple v-model:file-list="fileListY" :on-success="outUPloadY"
                action="http://localhost:5287/api/Breed/UploadFile" list-type="picture-card"
                :on-preview="handlePictureCardPreview" name="file">
                <el-icon>
                    <Plus />
                </el-icon>
            </el-upload>

            <el-dialog :visible.sync="dialogVisible" width="50%">
                <img :src="dialogImageUrl" class="preview-img" />
            </el-dialog>
        </span>

        <br />

        <div>
            <span style="font-weight: bolder;">
                企业信息&ensp;&ensp;&ensp;
                <el-button plain type="primary" @click="companyTu">设置</el-button>
            </span>

            <div>
                <span>
                    公司名称: {{ tcompanyshow.tcompanyName }}&ensp;&ensp;&ensp;
                    成立时间: {{ tcompanyshow.tcompanyTime }}
                </span>
                <br /><br />
                <span>
                    公司地址: {{ tcompanyshow.tcompanyProvince }}{{ tcompanyshow.tcompanyCity }}{{
                    tcompanyshow.tcompanyArea }}&ensp;&ensp;
                </span>
                <br /><br />
                <span>
                    公司简介: {{ tcompanyshow.tcompanyInfo }}
                </span>
            </div>
            <el-dialog v-model="dialogVisibletcompanyxiu" title="屠宰公司修改" width="500">
                <el-form :model="tcompanyupd" label-width="auto" style="max-width: 600px">
                    <el-form-item label="公司名称" prop="tcompanyName">
                        <el-input v-model="tcompanyupd.tcompanyName" />
                    </el-form-item>
                    <el-form-item label="成立时间" prop="tcompanyTime">
                        <el-input v-model="tcompanyupd.tcompanyTime" />
                    </el-form-item>
                    <el-form-item label="公司地址" prop="tcompanyProvince">
                        <el-select v-model="tcompanyupd.tcompanyProvince" placeholder="请选择" @change="citylist()">
                            <el-option v-for="item in provinces" :key="item.provinceId" :label="item.provinceName"
                                :value="item.provinceId" />
                        </el-select>

                        <el-select v-model="tcompanyupd.tcompanyCity" placeholder="请选择" @change="arealist()">
                            <el-option v-for="item in citys" :key="item.cityId" :label="item.cityName"
                                :value="item.cityId" />
                        </el-select>

                        <el-select v-model="tcompanyupd.tcompanyArea" placeholder="请选择">
                            <el-option v-for="item in areas" :key="item.areaId" :label="item.areaName"
                                :value="item.areaId" />
                        </el-select>
                    </el-form-item>
                    <el-form-item label="公司简介" prop="tcompanyInfo">
                        <el-input v-model="tcompanyupd.tcompanyInfo" />
                    </el-form-item>

                    <el-form-item>
                        <el-button type="primary" @click="tuxiu">保存</el-button>
                    </el-form-item>
                </el-form>
            </el-dialog>

            <br />
            <span style="font-weight: bolder;">
                企业照片&ensp;&ensp;&ensp;
                <el-upload multiple v-model:file-list="fileListY" :on-success="outUPloadY"
                    action="http://localhost:5287/api/Breed/UploadFile" list-type="picture-card"
                    :on-preview="handlePictureCardPreview" name="file">
                    <el-icon>
                        <Plus />
                    </el-icon>
                </el-upload>

                <el-dialog :visible.sync="dialogVisible" width="50%">
                    <img :src="dialogImageUrl" class="preview-img" />
                </el-dialog>
            </span>
        </div>


    </div>

    <div v-if="shen">
        <span style="font-weight: bolder;">
            深加工信息&ensp;&ensp;&ensp;
            <el-button plain type="primary" @click="machins">设置</el-button>
            <div>
                <span>
                    班组: {{ machinlist.machinClass }}&ensp;&ensp;&ensp;
                    负责人: {{ machinlist.machinFuZe }}
                </span>
            </div>
        </span>

        <el-dialog v-model="dialogVisibleshenadd" title="深加工信息添加" width="500">
            <el-form :model="machinadd" label-width="auto" style="max-width: 600px">
                <el-form-item label="班组" prop="butcherBatch">
                    <el-input v-model="machinadd.machinClass" />
                </el-form-item>
                <el-form-item label="负责人" prop="butcherWeight">
                    <el-input v-model="machinadd.machinFuZe" />
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" @click="shenadd">新增</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog v-model="dialogVisibleshenupd" title="深加工信息修改" width="500">
            <el-form :model="machinupd" label-width="auto" style="max-width: 600px">
                <el-form-item label="班组" prop="butcherBatch">
                    <el-input v-model="machinupd.machinClass" />
                </el-form-item>
                <el-form-item label="负责人" prop="butcherWeight">
                    <el-input v-model="machinupd.machinFuZe" />
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" @click="shenupd">保存</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>


        <br />
        <span style="font-weight: bolder;">
            食品安全信息&ensp;&ensp;&ensp;

        </span>

        <br /><br />
        <span style="font-weight: bolder;">
            供应商信息&ensp;&ensp;&ensp;
        </span>
        <br /> <br />
        <span style="font-weight: bolder;">
            原料&ensp;&ensp;&ensp;<br />
        </span>
        <span>
            生产批次: {{ goyishs.yuanlian }}<br />
            相关材料:<br />
            <div style="float: left;">
                <div style="left:100px;width: 100;">
                    <img :src="goyishs.flimage" style="width: 100px; height: 100px;" />
                </div>
            </div>
        </span>

        <br /> <br /> <br /> <br /> <br />
        <span style="font-weight: bolder;">
            辅料&ensp;&ensp;&ensp;<br />
        </span>
        <span>
            生产批次: {{ goyishs.fuLiao }}<br />
            相关材料: <br />
            <div style="float: left;">
                <div style="left:100px;width: 100;">
                    <img :src="goyishs.flimage" style="width: 100px; height: 100px;" />
                </div>
            </div>
        </span>

        <br /> <br /> <br /> <br /> <br />
        <span style="font-weight: bolder;">
            添加剂&ensp;&ensp;&ensp;<br />
        </span>
        <span>
            生产批次: {{ goyishs.tianjiaji }}<br />
            相关材料:<br />
            <div style="float: left;">
                <div style="left:100px;width: 100;">
                    <img :src="goyishs.flimage" style="width: 100px; height: 100px;" />
                </div>
            </div>
        </span>

        <br /> <br /> <br /> <br /> <br />
        <span style="font-weight: bolder;">
            包材&ensp;&ensp;&ensp;<br />
        </span>
        <span>
            生产批次: {{ goyishs.baocai }}<br />
            相关材料: <br />
            <div style="float: left;">
                <div style="left:100px;width: 100;">
                    <img :src="goyishs.flimage" style="width: 100px; height: 100px;" />
                </div>
            </div>
        </span>

        <br /> <br /> <br /> <br /> <br /> <br />
        <span style="font-weight: bolder;">
            企业信息&ensp;&ensp;&ensp;
            <el-button plain type="primary" @click="scompany">设置</el-button>
            <div>
                <span>
                    公司名称: {{ shencompanylist.machiningEnterpriseName }}&ensp;&ensp;&ensp;
                    生产许可证: {{ shencompanylist.machiningEnterpriseNumber }}
                </span>
            </div>
            <el-dialog v-model="dialogVisibleScompanyxiu" title="深加工企业信息修改" width="500">
                <el-form :model="machinupd" label-width="auto" style="max-width: 600px">
                    <el-form-item label="公司名称" prop="machiningEnterpriseName">
                        <el-input v-model="shencompanyupd.machiningEnterpriseName" />
                    </el-form-item>
                    <el-form-item label="生产许可证" prop="machiningEnterpriseNumber">
                        <el-input v-model="shencompanyupd.machiningEnterpriseNumber" />
                    </el-form-item>

                    <el-form-item>
                        <el-button type="primary" @click="shenupdss">保存</el-button>
                    </el-form-item>
                </el-form>
            </el-dialog>
        </span>
        <br />
        <span style="font-weight: bolder;">
            企业照片&ensp;&ensp;&ensp;
            <el-upload multiple v-model:file-list="fileListY" :on-success="outUPloadY"
                action="http://localhost:5287/api/Breed/UploadFile" list-type="picture-card"
                :on-preview="handlePictureCardPreview" name="file">
                <el-icon>
                    <Plus />
                </el-icon>
            </el-upload>

            <el-dialog :visible.sync="dialogVisible" width="50%">
                <img :src="dialogImageUrl" class="preview-img" />
            </el-dialog>
        </span>
    </div>


</template>
<script setup lang="ts">
import { reactive, ref, onMounted, inject } from 'vue'
import { type AxiosStatic } from 'axios';
const axios = inject('axios') as AxiosStatic;
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();
const ids = route.query.id
import { ElMessageBox, ElMessage } from 'element-plus'
import type { UploadProps, UploadUserFile } from "element-plus";
const dialogImageUrl = ref('')
const dialogVisible = ref(false)
const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
    dialogImageUrl.value = uploadFile.url!
    dialogVisible.value = true
}
onMounted(() => {
    GetGoodList();
    butcher();
    breed();
    machin();
    health();
    YCompany();
    Tcompany();
    provincess();
    //citylist();
    //arealist();
    shencompanys();
    gys();
    showphotoone();//动检图
    showphotooneY();//养殖企业照片
})

//屠宰显示
const tablelist: any = ref({})
const GetGoodList = () => {
    axios.get('/api/GoodInfo/GetGoodInfoImage?id=' + ids)
        .then(res => {
            tablelist.value = res.data
        })
}

import type { UploadFile } from 'element-plus'
const imageUrl = ref('')
const handleAvatarSuccess = (url: any) => {
    tablelist.goodImages = "http://localhost:5287" + url

    console.log(tablelist.goodImages)
}
const beforeAvatarUpload: UploadProps['beforeUpload'] = (rawFile) => {
    if (rawFile.type !== 'image/jpeg') {
        ElMessage.error('图片不能是jpeg类型的!')
        return false
    } else if (rawFile.size / 1024 / 1024 > 2) {
        ElMessage.error('图片大小不能超过2MB!')
        return false
    }
    return true
}

const yang = ref(false);
const tu = ref(false);
const shen = ref(false);

const yangs = () => {
    yang.value = true;
    tu.value = false;
    shen.value = false;
};
const tus = () => {
    yang.value = false;
    tu.value = true;
    shen.value = false;
};
const shens = () => {
    yang.value = false;
    tu.value = false;
    shen.value = true;
};

//养殖显示
const breedlist = reactive({
    "breedId": '',
    "breedName": "",
    "breedCome": "",
    "breedDay": "",
    "breedBrand": "",
    "breedPerson": "",
    "breedPut": "",
    "goodInfoId": ""
})
const breedadd = reactive({
    //"breedId": '',
    "breedName": "",
    "breedCome": "",
    "breedDay": "",
    "breedBrand": "",
    "breedPerson": "",
    "breedPut": "",
    "goodInfoId": ids
})
const breedupd = reactive({
    "breedId": '',
    "breedName": "",
    "breedCome": "",
    "breedDay": "",
    "breedBrand": "",
    "breedPerson": "",
    "breedPut": "",
    "goodInfoId": ids
})
const breed = () => {
    axios.get("/api/Breed/GetBreedShow?id=" + ids)
        .then(res => {
            console.log(res.data);
            breedlist.breedId = res.data[0].breedId;
            breedlist.breedName = res.data[0].breedName;
            breedlist.breedCome = res.data[0].breedCome;
            breedlist.breedDay = res.data[0].breedDay;
            breedlist.breedBrand = res.data[0].breedBrand;
            breedlist.breedPerson = res.data[0].breedPerson;
            breedlist.breedPut = res.data[0].breedPut;
            breedlist.goodInfoId = res.data[0].goodInfoId;
            breedupd.breedId = res.data[0].breedId;
            breedupd.breedName = res.data[0].breedName;
            breedupd.breedCome = res.data[0].breedCome;
            breedupd.breedDay = res.data[0].breedDay;
            breedupd.breedBrand = res.data[0].breedBrand;
            breedupd.breedPerson = res.data[0].breedPerson;
            breedupd.breedPut = res.data[0].breedPut;
            breedupd.goodInfoId = res.data[0].goodInfoId;

        })
}
const dialogVisibleyangadd = ref(false)
const dialogVisibleyanngxiu = ref(false)
const breeds = () => {
    if (breedlist.goodInfoId == "") {
        alert(111)
        dialogVisibleyangadd.value = true;

    } else {
        alert(222)
        //yangtu();
        dialogVisibleyanngxiu.value = true;

    }
}
const yangtu = () => {
    axios.get("/api/Breed/GetBreedFind?id=" + ids)
        .then(res => {
            breedupd.breedBrand = res.data.breedBrand,
                breedupd.breedCome = res.data.breedCome,
                breedupd.breedDay = res.data.breedDay,
                breedupd.breedName = res.data.breedName,
                breedupd.breedPerson = res.data.breedPerson,
                breedupd.breedPut = res.data.breedPut,
                breedupd.goodInfoId = res.data.goodInfoId,
                breedupd.breedId = res.data.breedId
        })
}
//修改
const yangxiu = () => {
    axios.post("/api/Breed/GetBreedUpd", breedupd)
        .then(res => {
            if (res.data > 0) {
                ElMessage.success({
                    message: '修改成功',
                    type: 'success'
                })
                dialogVisibleyanngxiu.value = false;
                GetGoodList();
                breed();
            }
            else {
                ElMessage.error({
                    message: '修改失败',
                    type: 'error'
                })
            }
        })
}
//添加
const yangadd = () => {
    axios.post("/api/Breed/GetBreedAdd", breedadd)
        .then(res => {
            if (res.data > 0) {
                ElMessage.success({
                    message: '添加成功',
                    type: 'success'
                })
                dialogVisibleyangadd.value = false;
                GetGoodList();
                breed();
            }
            else {
                ElMessage.error({
                    message: '添加失败',
                    type: 'error'
                })
            }
        })
}

const butcherlist = reactive({
    butcherId: "",
    butcherBatch: "",
    butcherWeight: "",
    butcherStime: "",
    butcherEtime: "",
    goodInfoId: "",
})
const butcheradd = reactive({
    //butcherId: "",
    butcherBatch: "",
    butcherWeight: "",
    butcherStime: "",
    butcherEtime: "",
    goodInfoId: ids,
})
const butcherupd = reactive({
    butcherId: "",
    butcherBatch: "",
    butcherWeight: "",
    butcherStime: "",
    butcherEtime: "",
    goodInfoId: ids,
})
const dialogVisibletuadd = ref(false)
const dialogVisibletuxiu = ref(false)
const butchers = () => {
    if (butcherlist.goodInfoId == "") {
        alert(111)
        dialogVisibletuadd.value = true;

    } else {
        alert(222)
        tufan();
        dialogVisibletuxiu.value = true;

    }
}
const butcher = () => {
    axios.get("/api/Butcher/GetButcherShow?id=" + ids)
        .then(res => {
            console.log(res.data);
            butcherlist.butcherBatch = res.data[0].butcherBatch,
                butcherlist.butcherWeight = res.data[0].butcherWeight,
                butcherlist.butcherStime = res.data[0].butcherStime,
                butcherlist.butcherEtime = res.data[0].butcherEtime,
                butcherlist.goodInfoId = res.data[0].goodInfoId,
                butcherlist.butcherId = res.data[0].butcherId

        })
}
const tufan = () => {
    axios.get("/api/Butcher/GetButcherFind?id=" + ids)
        .then(res => {
            console.log(res.data);
            butcherupd.butcherBatch = res.data.butcherBatch,
                butcherupd.butcherWeight = res.data.butcherWeight,
                butcherupd.butcherStime = res.data.butcherStime,
                butcherupd.butcherEtime = res.data.butcherEtime,
                butcherupd.goodInfoId = res.data.goodInfoId,
                butcherupd.butcherId = res.data.butcherId

        })
}

//修改
const tuxiu = () => {
    axios.post("/api/Butcher/GetButcherXiu", butcherupd)
        .then(res => {
            if (res.data > 0) {
                ElMessage.success({
                    message: '修改成功',
                    type: 'success'
                })
                dialogVisibletuxiu.value = false;
                GetGoodList();
                butcher();
            }
            else {
                ElMessage.error({
                    message: '修改失败',
                    type: 'error'
                })
            }
        })
}
//添加
const tuadd = () => {
    axios.post("/api/Butcher/GetButcherAdd", butcheradd)
        .then(res => {
            if (res.data > 0) {
                ElMessage.success({
                    message: '添加成功',
                    type: 'success'
                })
                dialogVisibletuadd.value = false;
                GetGoodList();
                butcher();
            }
            else {
                ElMessage.error({
                    message: '添加失败',
                    type: 'error'
                })
            }
        })
}

//多图片上传
const previewImages = ref([]);

const handleFileChange = (event: any) => {
    const files = event.target.files;
    for (let i = 0; i < files.length; i++) {
        const file = files[i];
        const reader = new FileReader();
        reader.onload = (e) => {
            previewImages.value.push(e.target.result);
        };
        reader.readAsDataURL(file);
    }
};

const uploadImages = async () => {
    const formData = new FormData();
    previewImages.value.forEach((imageDataURL, index) => {
        const blob = dataURLtoBlob(imageDataURL);
        formData.append(`image${index}`, blob);
    });

    try {
        await axios.post('http://localhost:5287/api/GoodInfo/Upload', formData, {
            headers: {
                'Content-Type': 'multipart/form-data',
            },
        });
        console.log('图片上传成功');
    } catch (error) {
        console.error('图片上传失败', error);
    }
};

function dataURLtoBlob(dataURL: any) {
    const arr = dataURL.split(',');
    const mime = arr[0].match(/:(.*?);/)[1];
    const bstr = atob(arr[1]);
    let n = bstr.length;
    const u8arr = new Uint8Array(n);
    while (n--) {
        u8arr[n] = bstr.charCodeAt(n);
    }
    return new Blob([u8arr], { type: mime });
}

//深加工显示
const machinlist = reactive({
    "machiningId": "",
    "machinClass": "",
    "machinFuZe": "",
    "goodInfoId": ""
})
const machinadd = reactive({
    //"machiningId": "",
    "machinClass": "",
    "machinFuZe": "",
    "goodInfoId": ids
})
const machinupd = reactive({
    "machiningId": "",
    "machinClass": "",
    "machinFuZe": "",
    "goodInfoId": ids
})
const dialogVisibleshenadd = ref(false)
const dialogVisibleshenupd = ref(false)
const machins = () => {
    if (machinlist.goodInfoId == "") {
        alert(111)
        dialogVisibleshenadd.value = true;

    } else {
        alert(222)
        shenfan();
        dialogVisibleshenupd.value = true;

    }
}
const machin = () => {
    axios.get("/api/Machin/GetMachinShow?id=" + ids)
        .then(res => {
            machinlist.machiningId = res.data[0].machiningId;
            machinlist.machinClass = res.data[0].machinClass;
            machinlist.machinFuZe = res.data[0].machinFuZe;
            machinlist.goodInfoId = res.data[0].goodInfoId;
        })
}


const shenfan = () => {
    axios.get("/api/Machin/GetMachinFind?id=" + ids)
        .then(res => {
            machinupd.machiningId = res.data.machiningId;
            machinupd.machinClass = res.data.machinClass;
            machinupd.machinFuZe = res.data.machinFuZe;
            machinupd.goodInfoId = res.data.goodInfoId;
        })
}

const shenadd = () => {
    axios.post("/api/Machin/GeMachinAdd", machinadd)
        .then(res => {
            if (res.data > 0) {
                ElMessage.success({
                    message: '添加成功',
                    type: 'success'
                })
                dialogVisibleshenadd.value = false;
                GetGoodList();
                machin();
            }
            else {
                ElMessage.error({
                    message: '添加失败',
                    type: 'error'
                })
            }
        })
}
const shenupd = () => {
    axios.post("/api/Machin/GetMachinUpd", machinupd)
        .then(res => {
            if (res.data > 0) {
                ElMessage.success({
                    message: '修改成功',
                    type: 'success'
                })
                dialogVisibleshenupd.value = false;
                GetGoodList();
                machin();
            }
            else {
                ElMessage.error({
                    message: '修改失败',
                    type: 'error'
                })
            }
        })
}

//显示保健
const healthlist = ref([])
const health = () => {
    axios.get("/api/Breed/GetHealthShow")
        .then(res => {
            healthlist.value = res.data;
        })
}
//修改保健
const healthupds = reactive({
    "healthId": "",
    "healthDay": "",
    "healthStyle": "",
    "healthIdea": "",
    "isDel": 0,
    "goodInfoId": ids
})
const dialogVisiblehealthxiu = ref(false)
const healthxiu = () => {
    healthfan();
    dialogVisiblehealthxiu.value = true;
}

const healthfan = () => {
    axios.get("/api/Breed/GetHealthFind?id=" + ids)
        .then(res => {
            healthupds.healthId = res.data.healthId;
            healthupds.healthDay = res.data.healthDay;
            healthupds.healthStyle = res.data.healthStyle;
            healthupds.healthIdea = res.data.healthIdea;
            healthupds.isDel = res.data.isDel;
            healthupds.goodInfoId = res.data.goodInfoId;
        })
}
const healthupd = () => {
    axios.post("/api/Breed/GetHealthUpd", healthupds)
        .then(res => {
            if (res.data > 0) {
                ElMessage.success({
                    message: '修改成功',
                    type: 'success'
                })
                dialogVisiblehealthxiu.value = false;
                GetGoodList();
                health();
            }
            else {
                ElMessage.error({
                    message: '修改失败',
                    type: 'error'
                })
            }
        })
}
//删除
const healthdel = (id: any) => {
    ElMessageBox.confirm(
        '确认要删除吗?',
        '警告',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
        }
    )
        .then(() => {
            axios.post("/api/Breed/GetHealthDel?id=" + id)
                .then(res => {
                    if (res.data > 0) {
                        ElMessage.success('删除成功')
                        GetGoodList();
                        health();
                    } else {
                        ElMessage.error('删除失败')
                    }
                })
        })
        .catch(() => {
            ElMessage({
                type: 'info',
                message: '取消删除',
            })
        })
}

//养殖企业信息
const ycompanyshow = reactive({
    "companyId": "",
    "companyName": "",
    "companyBoss": "",
    "companyNumber": ""
})
const ycompanyupd = reactive({
    "companyId": "",
    "companyName": "",
    "companyBoss": "",
    "companyNumber": ""
})
const YCompany = () => {
    axios.get("/api/Breed/GetYcompanShow")
        .then(res => {
            ycompanyshow.companyId = res.data[0].companyId;
            ycompanyshow.companyName = res.data[0].companyName;
            ycompanyshow.companyBoss = res.data[0].companyBoss;
            ycompanyshow.companyNumber = res.data[0].companyNumber;
            ycompanyupd.companyId = res.data[0].companyId;
            ycompanyupd.companyName = res.data[0].companyName;
            ycompanyupd.companyBoss = res.data[0].companyBoss;
            ycompanyupd.companyNumber = res.data[0].companyNumber;
        })
}
const dialogVisiblecompanyxiu = ref(false)
const yangcompany = () => {
    // yangcompanyfan();
    dialogVisiblecompanyxiu.value = true;

}
//反填
// const yangcompanyfan = () => {
//     axios.get("/api/Breed/GetYcompanyFind?id=" + ycompanyupd.companyId)
//         .then(res => {
//             ycompanyupd.companyId = res.data.companyId;
//             ycompanyupd.companyName = res.data.companyName;
//             ycompanyupd.companyBoss = res.data.companyBoss;
//             ycompanyupd.companyNumber = res.data.companyNumber;
//         })
// }
const Ycomanyupd = () => {
    axios.post("/api/Breed/GetYcompanyUpd", ycompanyupd)
        .then(res => {
            if (res.data > 0) {
                ElMessage.success({
                    message: "修改成功",
                    type: "success"
                })
                dialogVisiblecompanyxiu.value = false;
                YCompany();
            } else {
                ElMessage.error({
                    message: "修改失败",
                    type: "error"
                })
            }
        })
}

//屠宰公司反填
const tcompanyshow = reactive({
    "tcompanyId": "",
    "tcompanyName": "",
    "tcompanyTime": "",
    "tcompanyProvince": "",
    "provinceId": "",
    "tcompanyCity": "",
    "cityId": "",
    "tcompanyArea": "",
    "areaId": "",
    "tcompanyInfo": ""
})
const tcompanyupd = reactive({
    "tcompanyId": "",
    "tcompanyName": "",
    "tcompanyTime": "",
    "tcompanyProvince": "",
    "provinceId": "",
    "tcompanyCity": "",
    "cityId": "",
    "tcompanyArea": "",
    "areaId": "",
    "tcompanyInfo": ""
})
const Tcompany = () => {
    axios.get("/api/Butcher/GetTcompanies")
        .then(res => {
            tcompanyshow.tcompanyId = res.data[0].tcompanyId;
            tcompanyshow.tcompanyName = res.data[0].tcompanyName;
            tcompanyshow.tcompanyTime = res.data[0].tcompanyTime;
            tcompanyshow.tcompanyProvince = res.data[0].tcompanyProvince;
            tcompanyshow.provinceId = res.data[0].provinceId;
            tcompanyshow.tcompanyCity = res.data[0].tcompanyCity;
            tcompanyshow.cityId = res.data[0].cityId;
            tcompanyshow.tcompanyArea = res.data[0].tcompanyArea;
            tcompanyshow.areaId = res.data[0].areaId;
            tcompanyshow.tcompanyInfo = res.data[0].tcompanyInfo;

            tcompanyupd.tcompanyId = res.data[0].tcompanyId;
            tcompanyupd.tcompanyName = res.data[0].tcompanyName;
            tcompanyupd.tcompanyTime = res.data[0].tcompanyTime;
            tcompanyupd.tcompanyProvince = res.data[0].tcompanyProvince;
            tcompanyupd.provinceId = res.data[0].provinceId;
            provincess();
            tcompanyupd.tcompanyCity = res.data[0].tcompanyCity;
            tcompanyupd.cityId = res.data[0].cityId;
            citylist();
            tcompanyupd.tcompanyArea = res.data[0].tcompanyArea;
            tcompanyupd.areaId = res.data[0].areaId;
            arealist();
            tcompanyupd.tcompanyInfo = res.data[0].tcompanyInfo;
        })
}
const dialogVisibletcompanyxiu = ref(false)
const companyTu = () => {
    dialogVisibletcompanyxiu.value = true;
}
//省
const provinces: any = ref([])
const provincess = () => {
    axios.get("/api/Butcher/GetProvince")
        .then(res => {
            provinces.value = res.data
        })
}

//市
const citys: any = ref([])
const citylist = () => {
    console.log(tcompanyshow.provinceId);
    axios.get("/api/Butcher/GetCitie?provinceid=" + tcompanyshow.provinceId)
        .then(res => {
            citys.value = res.data
        })
}
//区
const areas: any = ref([])
const arealist = () => {
    console.log(tcompanyshow.cityId);
    axios.get("/api/Butcher/GetArea?cityid=" + tcompanyshow.cityId)
        .then(res => {
            areas.value = res.data
        })
}
//深加工公司反填+修改
const dialogVisibleScompanyxiu = ref(false)
const scompany = () => {
    dialogVisibleScompanyxiu.value = true;

}
//显示
const shencompanylist = reactive({
    "machiningEnterpriseId": "",
    "machiningEnterpriseName": "",
    "machiningEnterpriseNumber": ""
})
const shencompanyupd = reactive({
    "machiningEnterpriseId": "",
    "machiningEnterpriseName": "",
    "machiningEnterpriseNumber": ""
})
const shencompanys = () => {
    axios.get("/api/Machin/GetMachiningenterpriseShow")
        .then(res => {
            shencompanylist.machiningEnterpriseId = res.data[0].machiningEnterpriseId;
            shencompanylist.machiningEnterpriseName = res.data[0].machiningEnterpriseName;
            shencompanylist.machiningEnterpriseNumber = res.data[0].machiningEnterpriseNumber;

            shencompanyupd.machiningEnterpriseId = res.data[0].machiningEnterpriseId;
            shencompanyupd.machiningEnterpriseName = res.data[0].machiningEnterpriseName;
            shencompanyupd.machiningEnterpriseNumber = res.data[0].machiningEnterpriseNumber;
        })
}
//深加工公司修改
const shenupdss = () => {
    axios.post("/api/Machin/GetGongyingshangXiu", shencompanyupd)
        .then(res => {
            if (res.data > 0) {
                ElMessage.success({
                    message: "修改成功",
                    type: "success"
                })
                dialogVisibleScompanyxiu.value = false;
                shencompanys();
            } else {
                ElMessage.error({
                    message: "修改失败",
                    type: "error"
                })
            }
        })
}
//供应商显示
const goyishs = reactive({
    "gysid": "",
    "yuanlian": "",
    "ylimage": "",
    "fuLiao": "",
    "flimage": "",
    "tianjiaji": "",
    "tjjimage": "",
    "baocai": "",
    "baoCaiImage": ""
})
const gys = () => {
    axios.get("/api/Machin/GetGongyingshangShow")
        .then(res => {
            goyishs.gysid = res.data[0].gysid;
            goyishs.yuanlian = res.data[0].yuanlian;
            goyishs.ylimage = res.data[0].ylimage;
            goyishs.fuLiao = res.data[0].fuLiao;
            goyishs.flimage = res.data[0].flimage;
            goyishs.tianjiaji = res.data[0].tianjiaji;
        })
}

const fileList = ref<UploadUserFile[]>([
    {
        name: "",
        url: "",
    },
]);

const outUPload = (response: any) => {
    const uploadurl = { animalImages: response };
    axios.post("/api/Breed/GetAnimalAdd", uploadurl)
        .then(res => {
            if (res.data > 0) {
                ElMessage({
                    message: "添加成功",
                    type: "success"
                });
                GetGoodList(); // 你可能需要重新获取列表
                breed(); // 根据需要重新加载数据
                showphotoone(); // 刷新图片列表
            } else {
                ElMessage({
                    message: "添加失败",
                    type: "error"
                });
            }
        });
};


const showphotoone = () => {
    axios.get("/api/Breed/GetAnimalShow")
        .then(res => {
            fileList.value = res.data.map((item: any) => ({
                name: "http://localhost:5287/images/" + item.animalImages,
                url: "http://localhost:5287/images/" + item.animalImages,
            }));
        });
};


const fileListY = ref<UploadUserFile[]>([
    {
        name: "",
        url: "",
    },
]);

const outUPloadY = (response: any) => {
    const uploadurl = { yimageName: response };
    axios.post("/api/Breed/GetYimgAdd", uploadurl)
        .then(res => {
            if (res.data > 0) {
                ElMessage({
                    message: "添加成功",
                    type: "success"
                });
                GetGoodList(); // 你可能需要重新获取列表
                breed(); // 根据需要重新加载数据
                showphotooneY(); // 刷新图片列表
            } else {
                ElMessage({
                    message: "添加失败",
                    type: "error"
                });
            }
        });
};


const showphotooneY = () => {
    axios.get("/api/Breed/GetYimgShow")
        .then(res => {
            fileListY.value = res.data.map((item: any) => ({
                name: "http://localhost:5287/images/" + item.yimageName,
                url: "http://localhost:5287/images/" + item.yimageName,
            }));
        });
};

</script>
